﻿/*
SharePoint 2010 Central Admin - Command Search
By: Toni Frankola
http://www.sharepointusecases.com

Version: 1.5.0.0.
*/

$("#tags").autocomplete({
    source: results,
    minLength: 0,
    focus: function (event, ui) {
        $('#tags').val(ui.item.label);
        return false;
    },
    select: function (event, ui) {
        window.location = ui.item.desc
    }

});

function switchText() {
    if ($(this).val() == $(this).attr('title'))
        $(this).val('').removeClass('exampleText');
    else if ($.trim($(this).val()) == '')
        $(this).addClass('exampleText').val($(this).attr('title'));
}

$('#tags').each(function () {
    if ($.trim($(this).val()) == '') $(this).val($(this).attr('title'));
    if ($(this).val() == $(this).attr('title')) $(this).addClass('exampleText');
}).focus(switchText).blur(switchText);


// Custom String.format for JQuery, source: http://tinyurl.com/ycen4ky
String.format = function () {
    var s = arguments[0];
    for (var i = 0; i < arguments.length - 1; i++) {
        var reg = new RegExp("\\{" + i + "\\}", "gm");
        s = s.replace(reg, arguments[i + 1]);
    }

    return s;
}